package com.kuang.config;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor implements HandlerInterceptor {
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        Object user=request.getSession().getAttribute("userInfo");

        //提交登录
        if (request.getRequestURI().contains("login")){
            return true;
        }
        //什么情况下登录了
        if (user!=null){
            return true;
        }

        //判断什么情况下没有登录
        response.sendRedirect(request.getContextPath()+"/login.jsp");
        return false;
    }
}
